from haystack import indexes
from .models import Shoes


class ShoesIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=False)
    name = indexes.CharField(model_attr='name')
    price = indexes.CharField(model_attr='price')
    cate = indexes.CharField(model_attr='cate')

    def get_model(self):
        return Shoes

    def index_queryset(self, using=None):
        return self.get_model().objects.all()

    def prepare_text(self, obj):
        return f"{obj.name}{obj.price}"

